package aiku.numericalcontroloa.Controller.Products;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Model.Dto.SuppliersDto;
import aiku.numericalcontroloa.Service.Impl.SuppliersServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import aiku.numericalcontroloa.Model.Entity.Suppliers;

import java.util.List;

/**
 * 供应商控制层
 * @author 马文杰
 * @version 1.0
 */
@RestController
@RequestMapping("/suppliers")
@Slf4j
public class SuppliersController {
    @Autowired
    private SuppliersServiceImpl suppliersService;

    /**查询供应商列表
     * @param
     * @return
     */
    @RequestMapping("/list")
    public Result list(){
        List<Suppliers> suppliers = suppliersService.list();
        return Result.success(suppliers);
    }

    /**
     * 添加供应商
     * @param supplier
     */
    @RequestMapping("/add")
    public Result add(@RequestBody Suppliers supplier){
        Result  result =  suppliersService.add(supplier);
        return result;
    }

    /**
     * 获取供应商列表
     * 可根据供应商名称，电话，地址查询
     * 可根据省市区/县查询
     * @param suppliersDto
     * @return
     */
    @PostMapping("/getSuppliersList")
    public Result getSuppliersList(@RequestBody SuppliersDto suppliersDto){
        return suppliersService.getSuppliersList(suppliersDto);
    }

    /**
     * 添加供应商
     * @param suppliersDto
     * @return
     */
    @PostMapping("/addSuppliers")
    public Result addSuppliers(@RequestBody SuppliersDto suppliersDto){
        return suppliersService.addSuppliers(suppliersDto);
    }

    /**
     * 获取单个供应商
     * @param suppliersDto
     * @return
     */
    @PostMapping("/getSuppliers")
    public Result getSuppliers(@RequestBody SuppliersDto suppliersDto){
        return suppliersService.getSuppliers(suppliersDto);
    }

    /**
     * 获取单个供应商
     * 包括删除的
     * @param suppliersDto
     * @return
     */
    @PostMapping("/getSuppliersWithDelete")
    public Result getSuppliersWithDelete(@RequestBody SuppliersDto suppliersDto){
        return suppliersService.getSuppliersWithDelete(suppliersDto);
    }

    /**
     * 删除供应商
     * @param suppliersDto
     * @return
     */
    @PostMapping("/deleteSuppliers")
    public Result deleteSuppliers(@RequestBody SuppliersDto suppliersDto){
        return suppliersService.deleteSuppliers(suppliersDto);
    }

    /**
     * 修改供应商
     * @param suppliersDto
     * @return
     */
    @PostMapping("/updateSuppliers")
    public Result updateSuppliers(@RequestBody SuppliersDto suppliersDto){
        return suppliersService.updateSuppliers(suppliersDto);
    }
}
